import React from 'react'
import { Input } from 'antd'
import { useMySelector, useMyDispatch, MyShallEqual } from '../../../store'
import { setPassword } from '../../../store/modules/create'

const Password: React.FC = () => {
  const dispatch = useMyDispatch()
  const { password, isOpen } = useMySelector(
    (state) => ({
      password: state.code.password,
      isOpen: state.code.isOpen
    }),
    MyShallEqual
  )
  const onChange = (
    e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
  ) => {
    dispatch(setPassword(e.currentTarget.value))
  }

  return (
    <>
      <Input
        placeholder="请输入密码"
        allowClear
        onChange={onChange}
        value={password}
        disabled={isOpen}
      />
    </>
  )
}

export default Password
